#include "StdAfx.h"
#include "SequencedFrequencyProvider.h"

SequencedFrequencyProvider::SequencedFrequencyProvider(void)
{
	roundRobin = 0;
	curIdx = 0;
}

SequencedFrequencyProvider::~SequencedFrequencyProvider(void)
{
}

unsigned int SequencedFrequencyProvider::GetFrequency(short* sample, unsigned int length, std::vector<SampleMarker>* markers)
{
	unsigned int curFreq = freqs[roundRobin];
	unsigned int curDuration = durations[roundRobin];
	unsigned int currentDurationRemains = curDuration - curIdx;
	if(currentDurationRemains < length)
	{
		//next sound
		roundRobin = roundRobin+1 >= freqs.size() ?
			0 : roundRobin+1;

		curFreq = freqs[roundRobin];
		curIdx = length - currentDurationRemains;
	}
	else
	{
		//keep same sound and just move index
		curIdx += length;
	}
	return curFreq;
}

void SequencedFrequencyProvider::AddSequence(unsigned int frequency, unsigned int sampleCount)
{
	freqs.push_back(frequency);
	durations.push_back(sampleCount);
}
void SequencedFrequencyProvider::ClearSequences()
{
	freqs.clear();
	durations.clear();
}

